/***************************************************************************
 *   Copyright (C) 2009 by mj   *
 *   mj_dv@web.de   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

// startServer.cpp is a part of the steamserverutil project
// steamserverutil.googlecode.com



#include <QMessageBox>

#include "startServer.h"
#include "steamserverutil.h"






startServer::startServer(QWidget *parent)
        : QDialog(parent)
{
    setupUi(this);

    maxPlayersSpinBox->setRange(2, 32);

    util = new steamserverutil();
    if(!util->is_installed(comboBox))
        QMessageBox::critical(this, tr("Error, no servers found"), tr("Seems like that you have not got any servers installed\nPlease install one"), QMessageBox::Ok | QMessageBox::Default);

    connect(startButton, SIGNAL(clicked()), this, SLOT(start()));

}

void startServer::start()
{
    util->start_server(comboBox->currentIndex());

    command_to_start = util->param.c_str();
    workdir = util->workdir.c_str();


    if(util->server[comboBox->currentIndex()] == 13)
        workdir += "/server_darkmessiah";
    else if(util->server[comboBox->currentIndex()] > 13)
        workdir += "/servers_source";
    else if(util->server[comboBox->currentIndex()] > 0 && util->server[comboBox->currentIndex()] < 6)
        workdir += "/servers_source";
    else
        workdir += "/servers_hl1";

    if(disableVacCheckBox->isChecked())
        command_to_start += " -insecure";

    if(disableBotsCheckBox->isChecked())
        command_to_start += " -nobots";

    QString dummy = "%0";

    command_to_start += " +maxplayers " + dummy.arg(maxPlayersSpinBox->value()) + " +map " + mapEdit->text();

    if(onlyLanCheckBox->isChecked())
        command_to_start += " sv_lan 1";
}

